<template>
    <view>
        <painter @imgOK="onImgOK" :palette="imgDraw" style="position: absolute; top: -9999rpx"></painter>
    </view>
</template>

<script>
import painter from '../../pages/component/painter/painter.vue';
export default {
    components: {
        painter
    },
    data() {
        return {
            imgDraw: {},
            sharePath: ''
        };
    },
    props: {
        isCanDraw: {
            type: Boolean,
            default: false
        },
        content: ''
    },
    methods: {
        handleStartDrawImg: function () {
            uni.showLoading({
                title: '生成中'
            });
            this.setData({
                imgDraw: this.content
            });
          console.log('获取到值', this.imgDraw);
        },
        onImgErr: function (t) {
            uni.hideLoading();
            uni.showToast({
                title: '生成分享图失败，请刷新页面重试'
            });
            this.$emit('initData');
        },
        onImgOK: function (t) {
            uni.hideLoading();
            uni.showShareImageMenu({
                path: t.detail.path,
                fail: function (t) {
                    console.log(t);
                }
            });
            this.$emit('initData');
        }
    },
    created: function () {},
    watch: {
        isCanDraw: {
            handler: function (t) {
                if (t) {
                    this.handleStartDrawImg();
                }
            },

            immediate: true
        }
    }
};
</script>
<style>
@import 'index.css';
</style>
